package org.example.spring.self.demo.tl.c02.beanfactorypostprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * BeanFactory 后置处理器
 * 在 BeanDefinition 加载到容器中 还没有实例化
 */
@Component
public class TestBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("IoC 容器 调用了 TestBeanFactoryPostProcessor 的 postProcessBeanFactory 方法");
		for (String beanDefinitionName : beanFactory.getBeanDefinitionNames()) {
			if ("testLog".equals(beanDefinitionName)) {
				BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName);
				beanDefinition.setLazyInit(true);
			}
		}
	}
}
